package com.java1412.controller;

import com.java1412.entity.Payment;
import com.java1412.utils.CommonResult;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @author java1412
 * @create 2022-09-19 16:19
 */
@RestController
public class PaymentController {

    @Value("${server.port}")
    private String serverPort;

    // 自定义数据，免去连接数据库
    private static Map<Long, Payment> map = new HashMap<>();

    static {
        map.put(1L, new Payment(1L, "1111"));
        map.put(2L, new Payment(2L, "2222"));
        map.put(3L, new Payment(3L, "3333"));
    }

    @GetMapping("/paymentSQL/{id}")
    public CommonResult<Payment> paymentSQL(@PathVariable("id") Long id) {
        Payment payment = map.get(id);
        CommonResult<Payment> commonResult = new CommonResult<>(200, "from mysql,serverPort : " + serverPort, payment);
        return commonResult;
    }
}
